home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / RatePanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  38KB  |  1,399 lines

  1. /*
  2. **    RatePanel.c
  3. **
  4. **    Editing panel for phone units configuration
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_TIME,
  13.         GAD_FIRSTUNIT,GAD_PAY1,GAD_MINUTES1,
  14.         GAD_FOLLOWINGUNITS,GAD_PAY2,GAD_MINUTES2,
  15.         GAD_LIST,
  16.         GAD_ADDTIME,GAD_ADDDATE,GAD_EDIT,
  17.         GAD_REMOVETIME,GAD_ADDDAY,GAD_CLONE,
  18.         GAD_EDITTIME,GAD_IMPORT,GAD_REMOVE };
  19.  
  20. struct DoubleInfo
  21. {
  22.     LONG    GlyphWidth,
  23.         HeaderLen;
  24. };
  25.  
  26. STATIC struct DoubleInfo    DateInfo,
  27.                 TimeInfo;
  28.  
  29. STATIC struct Hook        DateHook,
  30.                 TimeHook;
  31.  
  32.     /* ListViewRender():
  33.      *
  34.      *    This callback routine is responsible for rendering
  35.      *    the single listview entries.
  36.      */
  37.  
  38. STATIC ULONG __saveds __asm
  39. ListViewRender(register __a0 struct Hook *Hook,register __a1 struct LVDrawMsg *Msg,register __a2 struct Node *Node)
  40. {
  41.         /* We only know how to redraw lines. */
  42.  
  43.     if(Msg -> lvdm_MethodID == LV_DRAW)
  44.     {
  45.         struct RastPort        *RPort    = Msg -> lvdm_RastPort;
  46.         LONG             Left    = Msg -> lvdm_Bounds . MinX,
  47.                      Top    = Msg -> lvdm_Bounds . MinY,
  48.                      Width    = Msg -> lvdm_Bounds . MaxX - Msg -> lvdm_Bounds . MinX + 1,
  49.                      Height    = Msg -> lvdm_Bounds . MaxY - Msg -> lvdm_Bounds . MinY + 1,
  50.                      Delta,
  51.                      FgPen,BgPen,
  52.                      Len,LabelLen,Template;
  53.         UBYTE            *String,Header[8];
  54.         struct DoubleInfo    *Info;
  55.  
  56.         Info = Hook -> h_Data;
  57.  
  58.         String = &Node -> ln_Name[Info -> HeaderLen];
  59.  
  60.         memcpy(Header,Node -> ln_Name,Info -> HeaderLen);
  61.  
  62.         Header[Info -> HeaderLen] = 0;
  63.  
  64.             /* Determine the rendering pens. */
  65.  
  66.         switch(Msg -> lvdm_State)
  67.         {
  68.             case LVR_SELECTEDDISABLED:
  69.             case LVR_NORMALDISABLED:
  70.             case LVR_NORMAL:
  71.  
  72.                 FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[TEXTPEN];
  73.                 BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[BACKGROUNDPEN];
  74.                 break;
  75.  
  76.             case LVR_SELECTED:
  77.  
  78.                 FgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLTEXTPEN];
  79.                 BgPen = Msg -> lvdm_DrawInfo -> dri_Pens[FILLPEN];
  80.                 break;
  81.         }
  82.  
  83.         SetAPen(RPort,BgPen);
  84.         RectFill(RPort,Left,Top,Left + 1,Top + Height - 1);
  85.  
  86.         Left    += 2;
  87.         Width    -= 2;
  88.  
  89.             /* Set the rendering pens. */
  90.  
  91.         SetDrMd(RPort,JAM2);
  92.         SetBPen(RPort,BgPen);
  93.  
  94.         Template = Info -> HeaderLen * Info -> GlyphWidth;
  95.  
  96.             /* Determine header length. */
  97.  
  98.         Len = TextLength(RPort,Header,Info -> HeaderLen);
  99.  
  100.             /* Fill the space to precede the header. */
  101.  
  102.         if((Delta = Template - Len) > 0)
  103.         {
  104.             SetAPen(RPort,BgPen);
  105.             RectFill(RPort,Left,Top,Left + Delta - 1,Top + Height - 1);
  106.         }
  107.  
  108.             /* Render the header, right-justified. */
  109.  
  110.         SetAPen(RPort,FgPen);
  111.  
  112.         Move(RPort,Left + Delta,Top + RPort -> Font -> tf_Baseline);
  113.         Text(RPort,Header,Info -> HeaderLen);
  114.  
  115.             /* Adjust width and area left edge. */
  116.  
  117.         Left    += Template;
  118.         Width    -= Template;
  119.  
  120.             /* Determine length of vanilla name. */
  121.  
  122.         LabelLen = strlen(String);
  123.  
  124.             /* Try to make it fit. */
  125.  
  126.         while(LabelLen > 0 && (Len = TextLength(RPort,String,LabelLen)) > Width)
  127.             LabelLen--;
  128.  
  129.             /* Print the vanilla name if possible. */
  130.  
  131.         if(LabelLen)
  132.         {
  133.             Move(RPort,Left,Top + RPort -> Font -> tf_Baseline);
  134.             Text(RPort,String,LabelLen);
  135.  
  136.             Left    += Len;
  137.             Width    -= Len;
  138.         }
  139.  
  140.             /* Fill the area to follow the vanilla name. */
  141.  
  142.         if(Width > 0)
  143.         {
  144.             SetAPen(RPort,BgPen);
  145.             RectFill(RPort,Left,Top,Left + Width - 1,Top + Height - 1);
  146.         }
  147.  
  148.             /* If the item happens to be disabled, draw the cross-hatch
  149.              * pattern across it.
  150.              */
  151.  
  152.         if(Msg -> lvdm_State == LVR_SELECTEDDISABLED || Msg -> lvdm_State == LVR_NORMALDISABLED)
  153.         {
  154.             SetDrMd(RPort,JAM1);
  155.  
  156.             SetAPen(RPort,Msg -> lvdm_DrawInfo -> dri_Pens[BLOCKPEN]);
  157.  
  158.             SetAfPt(RPort,(UWORD *)&Ghosting,1);
  159.  
  160.             RectFill(RPort,Msg -> lvdm_Bounds . MinX,Msg -> lvdm_Bounds . MinY,Msg -> lvdm_Bounds . MaxX,Msg -> lvdm_Bounds . MaxY);
  161.  
  162.             SetAfPt(RPort,NULL,0);
  163.         }
  164.  
  165.         return(LVCB_OK);
  166.     }
  167.     else
  168.         return(LVCB_UNKNOWN);
  169. }
  170.  
  171. STATIC struct Gadget *
  172. CreateAllGadgets(struct PhoneEntry *Entry,struct Gadget **GadgetArray,struct Gadget **GadgetList)
  173. {
  174.     struct Gadget        *Gadget;
  175.     struct NewGadget     NewGadget;
  176.     UWORD             Counter = 0;
  177.  
  178.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  179.  
  180.     memset(&NewGadget,0,sizeof(struct NewGadget));
  181.  
  182.     if(Gadget = CreateContext(GadgetList))
  183.     {
  184.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_TIME_GAD);
  185.         NewGadget . ng_GadgetID        = Counter;
  186.         NewGadget . ng_Flags        = PLACETEXT_ABOVE|NG_HIGHLABEL;
  187.  
  188.         TimeInfo . GlyphWidth    = SZ_GetNumericLen("1");
  189.         TimeInfo . HeaderLen    = 2;
  190.  
  191.         TimeHook . h_Entry    = (LONG (*)())ListViewRender;
  192.         TimeHook . h_Data    = &TimeInfo;
  193.  
  194.         GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
  195.             SZ_Adjust,        TRUE,
  196.             SZ_Lines,        7,
  197.             SZ_Chars,        5,
  198.             GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,        TRUE,
  199.  
  200.             GTLV_CallBack,        &TimeHook,
  201.             GTLV_ShowSelected,    NULL,
  202.         TAG_DONE);
  203.  
  204.         SZ_SetWidth(SZ_Width(STRING_KIND,NULL,10,NULL));
  205.  
  206.         SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_RATEPANEL_PAY_PER_UNIT_GAD,MSG_RATEPANEL_FOLLOWING_UNITS_GAD));
  207.  
  208.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_FIRST_UNIT_GAD);
  209.         NewGadget . ng_GadgetID        = Counter;
  210.         NewGadget . ng_Flags        = NG_HIGHLABEL;
  211.  
  212.         GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  213.             SZ_Adjust,        TRUE,
  214.             SZ_AutoWidth,        TRUE,
  215.             SZ_NewColumn,        TRUE,
  216.         TAG_DONE);
  217.  
  218.         NewGadget . ng_GadgetText    = SmallCurrency();
  219.         NewGadget . ng_GadgetID        = Counter;
  220.         NewGadget . ng_Flags        = 0;
  221.  
  222.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  223.             SZ_Adjust,    TRUE,
  224.             SZ_AutoWidth,    TRUE,
  225.  
  226.             GTIN_MaxChars,    8,
  227.             GA_Disabled,    TRUE,
  228.         TAG_DONE);
  229.  
  230.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_SECONDS_PER_UNIT_GAD);
  231.         NewGadget . ng_GadgetID        = Counter;
  232.  
  233.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  234.             SZ_Adjust,    TRUE,
  235.             SZ_AutoWidth,    TRUE,
  236.  
  237.             GTIN_MaxChars,    8,
  238.             GA_Disabled,    TRUE,
  239.         TAG_DONE);
  240.  
  241.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_FOLLOWING_UNITS_GAD);
  242.         NewGadget . ng_GadgetID        = Counter;
  243.         NewGadget . ng_Flags        = NG_HIGHLABEL;
  244.  
  245.         GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  246.             SZ_Adjust,    TRUE,
  247.             SZ_AutoWidth,    TRUE,
  248.         TAG_DONE);
  249.  
  250.         NewGadget . ng_GadgetText    = SmallCurrency();
  251.         NewGadget . ng_GadgetID        = Counter;
  252.         NewGadget . ng_Flags        = 0;
  253.  
  254.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  255.             SZ_Adjust,    TRUE,
  256.             SZ_AutoWidth,    TRUE,
  257.  
  258.             GTIN_MaxChars,    8,
  259.             GA_Disabled,    TRUE,
  260.         TAG_DONE);
  261.  
  262.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_SECONDS_PER_UNIT_GAD);
  263.         NewGadget . ng_GadgetID        = Counter;
  264.  
  265.         GadgetArray[Counter++] = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  266.             SZ_Adjust,    TRUE,
  267.             SZ_AutoWidth,    TRUE,
  268.  
  269.             GTIN_MaxChars,    8,
  270.             GA_Disabled,    TRUE,
  271.         TAG_DONE);
  272.  
  273.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_DAYS_AND_DATES_GAD);
  274.         NewGadget . ng_GadgetID        = Counter;
  275.         NewGadget . ng_Flags        = PLACETEXT_ABOVE|NG_HIGHLABEL;
  276.  
  277.         DateInfo . GlyphWidth    = SZ_GetLen("1");
  278.         DateInfo . HeaderLen    = 7;
  279.  
  280.         DateHook . h_Entry    = (LONG (*)())ListViewRender;
  281.         DateHook . h_Data    = &DateInfo;
  282.  
  283.         GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
  284.             SZ_Adjust,        TRUE,
  285.             SZ_NewColumn,        TRUE,
  286.             SZ_Lines,        7,
  287.             SZ_Chars,        30,
  288.  
  289.             GTLV_CallBack,        &DateHook,
  290.             GTLV_Labels,        &Entry -> TimeDateList,
  291.             GTLV_ShowSelected,    NULL,
  292.         TAG_DONE);
  293.  
  294.         SZ_ResetMaxWidth();
  295.  
  296.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_TIME_GAD),0,NULL);
  297.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_REMOVE_TIME_GAD),0,NULL);
  298.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_EDIT_TIME_GAD),0,NULL);
  299.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_DATE_GAD),0,NULL);
  300.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_ADD_DAYS_GAD),0,NULL);
  301.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_IMPORT_GAD),0,NULL);
  302.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_EDIT_GAD),0,NULL);
  303.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_RATEPANEL_CLONE_GAD),0,NULL);
  304.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_REMOVE_GAD),0,NULL);
  305.  
  306.         SZ_SetWidth(SZ_ResetMaxWidth());
  307.  
  308.  
  309.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_ADD_TIME_GAD);
  310.         NewGadget . ng_GadgetID        = Counter;
  311.         NewGadget . ng_Flags        = PLACETEXT_IN;
  312.  
  313.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  314.             SZ_Adjust,    TRUE,
  315.             SZ_AutoWidth,    TRUE,
  316.             SZ_AlignExtra,    TRUE,
  317.             SZ_AlignBottom,    TRUE,
  318.             SZ_GroupCount,    3,
  319.  
  320.             GA_Disabled,    TRUE,
  321.         TAG_DONE);
  322.  
  323.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_ADD_DATE_GAD);
  324.         NewGadget . ng_GadgetID        = Counter;
  325.  
  326.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  327.             SZ_Adjust,    TRUE,
  328.             SZ_AutoWidth,    TRUE,
  329.             SZ_GroupNext,    TRUE,
  330.         TAG_DONE);
  331.  
  332.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_EDIT_GAD);
  333.         NewGadget . ng_GadgetID        = Counter;
  334.  
  335.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  336.             SZ_Adjust,    TRUE,
  337.             SZ_AutoWidth,    TRUE,
  338.             SZ_GroupNext,    TRUE,
  339.  
  340.             GA_Disabled,    TRUE,
  341.         TAG_DONE);
  342.  
  343.  
  344.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_REMOVE_TIME_GAD);
  345.         NewGadget . ng_GadgetID        = Counter;
  346.  
  347.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  348.             SZ_Adjust,    TRUE,
  349.             SZ_AutoWidth,    TRUE,
  350.             SZ_AlignBottom,    TRUE,
  351.             SZ_GroupCount,    3,
  352.  
  353.             GA_Disabled,    TRUE,
  354.         TAG_DONE);
  355.  
  356.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_ADD_DAYS_GAD);
  357.         NewGadget . ng_GadgetID        = Counter;
  358.  
  359.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  360.             SZ_Adjust,    TRUE,
  361.             SZ_AutoWidth,    TRUE,
  362.             SZ_GroupNext,    TRUE,
  363.         TAG_DONE);
  364.  
  365.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_CLONE_GAD);
  366.         NewGadget . ng_GadgetID        = Counter;
  367.  
  368.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  369.             SZ_Adjust,    TRUE,
  370.             SZ_AutoWidth,    TRUE,
  371.             SZ_GroupNext,    TRUE,
  372.  
  373.             GA_Disabled,    TRUE,
  374.         TAG_DONE);
  375.  
  376.  
  377.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_EDIT_TIME_GAD);
  378.         NewGadget . ng_GadgetID        = Counter;
  379.  
  380.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  381.             SZ_Adjust,    TRUE,
  382.             SZ_AutoWidth,    TRUE,
  383.             SZ_AlignBottom,    TRUE,
  384.             SZ_GroupCount,    3,
  385.  
  386.             GA_Disabled,    TRUE,
  387.         TAG_DONE);
  388.  
  389.         NewGadget . ng_GadgetText    = LocaleString(MSG_RATEPANEL_IMPORT_GAD);
  390.         NewGadget . ng_GadgetID        = Counter;
  391.  
  392.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  393.             SZ_Adjust,    TRUE,
  394.             SZ_AutoWidth,    TRUE,
  395.             SZ_GroupNext,    TRUE,
  396.  
  397.             GA_Disabled,    NumPhoneEntries < 2,
  398.         TAG_DONE);
  399.  
  400.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_REMOVE_GAD);
  401.         NewGadget . ng_GadgetID        = Counter;
  402.  
  403.         GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  404.             SZ_Adjust,    TRUE,
  405.             SZ_AutoWidth,    TRUE,
  406.             SZ_GroupNext,    TRUE,
  407.  
  408.             GA_Disabled,    TRUE,
  409.         TAG_DONE);
  410.     }
  411.  
  412.     return(Gadget);
  413. }
  414.  
  415. STATIC VOID __regargs
  416. DisableGadgets(struct Gadget **GadgetArray,struct Window *PanelWindow,BYTE Mode)
  417. {
  418.     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  419.         GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    Mode,
  420.     TAG_DONE);
  421.  
  422.     GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
  423.         GA_Disabled,    Mode,
  424.     TAG_DONE);
  425.  
  426.     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
  427.         GA_Disabled,    Mode,
  428.     TAG_DONE);
  429.  
  430.     GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
  431.         GA_Disabled,    Mode,
  432.     TAG_DONE);
  433.  
  434.     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
  435.         GA_Disabled,    Mode,
  436.     TAG_DONE);
  437.  
  438.     if(Mode)
  439.         ActiveGadget = NULL;
  440. }
  441.  
  442. STATIC struct Node * __regargs
  443. GetNode(struct List *List,LONG Offset)
  444. {
  445.     struct Node    *Node;
  446.     LONG         i;
  447.  
  448.     Node = (struct Node *)List -> lh_Head;
  449.  
  450.     for(i = 0 ; i < Offset ; i++)
  451.     {
  452.         if(!Node -> ln_Succ -> ln_Succ)
  453.             return(NULL);
  454.  
  455.         Node = Node -> ln_Succ;
  456.     }
  457.  
  458.     return(Node);
  459. }
  460.  
  461. BYTE
  462. RatePanel(struct List *PhoneList,struct PhoneEntry *Entry)
  463. {
  464.     struct Window    *PanelWindow;
  465.     struct Gadget    *GadgetList;
  466.     struct Gadget    *GadgetArray[GAD_REMOVE + 1];
  467.     BYTE         MadeChanges = FALSE;
  468.  
  469.     if(CreateAllGadgets(Entry,GadgetArray,&GadgetList))
  470.     {
  471.         if(PanelWindow = OpenWindowTags(NULL,
  472.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  473.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  474.             WA_Width,    SZ_GetWindowWidth(),
  475.             WA_Height,    SZ_GetWindowHeight(),
  476.  
  477.             WA_Activate,    TRUE,
  478.             WA_DragBar,    TRUE,
  479.             WA_DepthGadget,    TRUE,
  480.             WA_RMBTrap,    TRUE,
  481.             WA_DepthGadget,    TRUE,
  482.             WA_CloseGadget,    TRUE,
  483.             WA_CustomScreen,Window -> WScreen,
  484.             WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_VANILLAKEY | BUTTONIDCMP | INTEGERIDCMP | LISTVIEWIDCMP,
  485.             WA_Title,    LocaleString(MSG_RATEPANEL_RATES_PREFERENCES_TXT),
  486.         TAG_DONE))
  487.         {
  488.             struct IntuiMessage    *Massage;
  489.             ULONG             IClass,Code;
  490.             struct Gadget        *Gadget;
  491.             BYTE             Terminated = FALSE;
  492.             LONG             Selected = ~0,Count = 0,TimeSelected = ~0;
  493.             struct TimeDateNode    *TimeDateNode,*NewNode;
  494.             struct List        *TimeList = NULL;
  495.  
  496.             GuideContext(CONTEXT_RATES);
  497.  
  498.             TimeDateNode = (struct TimeDateNode *)Entry -> TimeDateList . mlh_Head;
  499.  
  500.             while(TimeDateNode -> VanillaNode . ln_Succ)
  501.             {
  502.                 Count++;
  503.  
  504.                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  505.             }
  506.  
  507.             PushWindow(PanelWindow);
  508.  
  509.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  510.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  511.             GT_RefreshWindow(PanelWindow,NULL);
  512.  
  513.             ActiveGadget = NULL;
  514.  
  515.             ClrSignal(SIG_BREAK);
  516.  
  517.             while(!Terminated)
  518.             {
  519.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  520.                     break;
  521.  
  522.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  523.                 {
  524.                     IClass    = Massage -> Class;
  525.                     Code    = Massage -> Code;
  526.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  527.  
  528.                     GT_ReplyIMsg(Massage);
  529.  
  530.                     KeySelect(GadgetArray,GAD_REMOVE,Code,PanelWindow,&Gadget,&IClass,&Code);
  531.  
  532.                     if(IClass == IDCMP_GADGETDOWN)
  533.                     {
  534.                         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  535.                             ActiveGadget = Gadget;
  536.                     }
  537.  
  538.                     if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
  539.                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  540.  
  541.                     if(IClass == IDCMP_CLOSEWINDOW)
  542.                         Terminated = TRUE;
  543.  
  544.                     if(IClass == IDCMP_GADGETUP)
  545.                     {
  546.                         switch(Gadget -> GadgetID)
  547.                         {
  548.                             case GAD_TIME:
  549.  
  550.                                 TimeSelected = Code;
  551.  
  552.                                 if(Selected != ~0)
  553.                                 {
  554.                                     GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
  555.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
  556.                                     TAG_DONE);
  557.  
  558.                                     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
  559.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
  560.                                     TAG_DONE);
  561.  
  562.                                     GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
  563.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
  564.                                     TAG_DONE);
  565.  
  566.                                     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
  567.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
  568.                                     TAG_DONE);
  569.                                 }
  570.  
  571.                                 break;
  572.  
  573.                             case GAD_EDITTIME:
  574.  
  575.                                 if(Selected != ~0 && TimeSelected != ~0)
  576.                                 {
  577.                                     UBYTE Time = TimeDateNode -> Table[TimeSelected] . Time;
  578.  
  579.                                     BlockWindow(PanelWindow);
  580.  
  581.                                     if(TimePanel(&TimeDateNode -> Table[TimeSelected] . Time))
  582.                                     {
  583.                                         struct List *NewTimeList;
  584.  
  585.                                         MadeChanges = TRUE;
  586.  
  587.                                         SortTimeTable(TimeDateNode);
  588.  
  589.                                         if(NewTimeList = BuildTimeList(TimeDateNode))
  590.                                         {
  591.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  592.                                                 GTLV_Labels,    ~0,
  593.                                             TAG_DONE);
  594.  
  595.                                             if(TimeList)
  596.                                                 FreeVec(TimeList);
  597.  
  598.                                             TimeList = NewTimeList;
  599.  
  600.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  601.                                                 GTLV_Labels,    TimeList,
  602.                                                 GTLV_Selected,    0,
  603.                                                 GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  604.                                             TAG_DONE);
  605.  
  606.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  607.                                                 GTLV_Labels,    ~0,
  608.                                             TAG_DONE);
  609.  
  610.                                             DisableGadgets(GadgetArray,PanelWindow,TRUE);
  611.  
  612.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  613.                                                 GA_Disabled,    TRUE,
  614.                                             TAG_DONE);
  615.  
  616.                                             GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  617.                                                 GA_Disabled,    TRUE,
  618.                                             TAG_DONE);
  619.  
  620.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  621.                                                 GA_Disabled,    TRUE,
  622.                                             TAG_DONE);
  623.  
  624.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  625.                                                 GTLV_Labels,    &Entry -> TimeDateList,
  626.                                                 GTLV_Selected,    ~0,
  627.                                             TAG_DONE);
  628.  
  629.                                             Selected = ~0;
  630.  
  631.                                             ActiveGadget = NULL;
  632.  
  633.                                             TimeSelected = ~0;
  634.  
  635.                                             GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  636.                                                 GA_Disabled,    TRUE,
  637.                                             TAG_DONE);
  638.  
  639.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  640.                                                 GA_Disabled,    TRUE,
  641.                                             TAG_DONE);
  642.  
  643.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  644.                                                 GA_Disabled,    TRUE,
  645.                                             TAG_DONE);
  646.                                         }
  647.                                         else
  648.                                         {
  649.                                             TimeDateNode -> Table[TimeSelected] . Time = Time;
  650.  
  651.                                             SortTimeTable(TimeDateNode);
  652.  
  653.                                             DisplayBeep(PanelWindow -> WScreen);
  654.                                         }
  655.                                     }
  656.  
  657.                                     ReleaseWindow(PanelWindow);
  658.                                 }
  659.  
  660.                                 break;
  661.  
  662.                             case GAD_REMOVETIME:
  663.  
  664.                                 if(Selected != ~0 && TimeSelected != ~0)
  665.                                 {
  666.                                     MadeChanges = TRUE;
  667.  
  668.                                     BlockWindow(PanelWindow);
  669.  
  670.                                     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  671.                                         GTLV_Labels,    ~0,
  672.                                     TAG_DONE);
  673.  
  674.                                     if(DeleteTimeDateNode(TimeDateNode,TimeSelected))
  675.                                     {
  676.                                         if(TimeList)
  677.                                             FreeVec(TimeList);
  678.  
  679.                                         if(TimeList = BuildTimeList(TimeDateNode))
  680.                                         {
  681.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  682.                                                 GTLV_Labels,    TimeList,
  683.                                                 GTLV_Selected,    0,
  684.                                                 GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  685.                                             TAG_DONE);
  686.  
  687.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  688.                                                 GTLV_Labels,    ~0,
  689.                                             TAG_DONE);
  690.  
  691.                                             DisableGadgets(GadgetArray,PanelWindow,TRUE);
  692.  
  693.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  694.                                                 GA_Disabled,    TRUE,
  695.                                             TAG_DONE);
  696.  
  697.                                             GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  698.                                                 GA_Disabled,    TRUE,
  699.                                             TAG_DONE);
  700.  
  701.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  702.                                                 GA_Disabled,    TRUE,
  703.                                             TAG_DONE);
  704.  
  705.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  706.                                                 GTLV_Labels,    &Entry -> TimeDateList,
  707.                                                 GTLV_Selected,    ~0,
  708.                                             TAG_DONE);
  709.  
  710.                                             Selected = ~0;
  711.  
  712.                                             ActiveGadget = NULL;
  713.  
  714.                                             TimeSelected = ~0;
  715.  
  716.                                             GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  717.                                                 GA_Disabled,    TRUE,
  718.                                             TAG_DONE);
  719.  
  720.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  721.                                                 GA_Disabled,    TRUE,
  722.                                             TAG_DONE);
  723.  
  724.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  725.                                                 GA_Disabled,    TRUE,
  726.                                             TAG_DONE);
  727.                                         }
  728.                                         else
  729.                                         {
  730.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  731.                                                 GTLV_Labels,    &EmptyList,
  732.                                             TAG_DONE);
  733.  
  734.                                             DisplayBeep(PanelWindow -> WScreen);
  735.                                         }
  736.                                     }
  737.                                     else
  738.                                     {
  739.                                         GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  740.                                             GTLV_Labels,    TimeList,
  741.                                             GTLV_Selected,    TimeSelected,
  742.                                         TAG_DONE);
  743.  
  744.                                         DisplayBeep(PanelWindow -> WScreen);
  745.                                     }
  746.  
  747.                                     ReleaseWindow(PanelWindow);
  748.                                 }
  749.  
  750.                                 break;
  751.  
  752.                             case GAD_ADDTIME:
  753.  
  754.                                 if(Selected != ~0)
  755.                                 {
  756.                                     UBYTE Time = DT_GET_TIME(12,0);
  757.  
  758.                                     MadeChanges = TRUE;
  759.  
  760.                                     BlockWindow(PanelWindow);
  761.  
  762.                                     if(TimePanel(&Time))
  763.                                     {
  764.                                         BYTE AddIt = TRUE;
  765.                                         LONG i;
  766.  
  767.                                         for(i = 0 ; i < TimeDateNode -> Table[0] . Count ; i++)
  768.                                         {
  769.                                             if(Time == TimeDateNode -> Table[i] . Time)
  770.                                             {
  771.                                                 AddIt = FALSE;
  772.                                                 break;
  773.                                             }
  774.                                         }
  775.  
  776.                                         if(AddIt)
  777.                                         {
  778.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  779.                                                 GTLV_Labels,    ~0,
  780.                                             TAG_DONE);
  781.  
  782.                                             if(ResizeTimeDateNode(TimeDateNode,TimeDateNode -> Table[0] . Count + 1,Time))
  783.                                             {
  784.                                                 SortTimeTable(TimeDateNode);
  785.  
  786.                                                 if(TimeList)
  787.                                                     FreeVec(TimeList);
  788.  
  789.                                                 if(TimeList = BuildTimeList(TimeDateNode))
  790.                                                 {
  791.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  792.                                                         GTLV_Labels,    TimeList,
  793.                                                         GTLV_Selected,    0,
  794.                                                         GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  795.                                                     TAG_DONE);
  796.  
  797.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  798.                                                         GTLV_Labels,    ~0,
  799.                                                     TAG_DONE);
  800.  
  801.                                                     DisableGadgets(GadgetArray,PanelWindow,TRUE);
  802.  
  803.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  804.                                                         GA_Disabled,    TRUE,
  805.                                                     TAG_DONE);
  806.  
  807.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  808.                                                         GA_Disabled,    TRUE,
  809.                                                     TAG_DONE);
  810.  
  811.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  812.                                                         GA_Disabled,    TRUE,
  813.                                                     TAG_DONE);
  814.  
  815.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  816.                                                         GTLV_Labels,    &Entry -> TimeDateList,
  817.                                                         GTLV_Selected,    ~0,
  818.                                                     TAG_DONE);
  819.  
  820.                                                     Selected = ~0;
  821.  
  822.                                                     ActiveGadget = NULL;
  823.  
  824.                                                     TimeSelected = ~0;
  825.  
  826.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  827.                                                         GA_Disabled,    TRUE,
  828.                                                     TAG_DONE);
  829.  
  830.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  831.                                                         GA_Disabled,    TRUE,
  832.                                                     TAG_DONE);
  833.  
  834.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  835.                                                         GA_Disabled,    TRUE,
  836.                                                     TAG_DONE);
  837.                                                 }
  838.                                                 else
  839.                                                 {
  840.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  841.                                                         GTLV_Labels,    &EmptyList,
  842.                                                     TAG_DONE);
  843.  
  844.                                                     DisplayBeep(PanelWindow -> WScreen);
  845.                                                 }
  846.                                             }
  847.                                             else
  848.                                             {
  849.                                                 GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  850.                                                     GTLV_Labels,    TimeList,
  851.                                                     GTLV_Selected,    TimeSelected,
  852.                                                 TAG_DONE);
  853.  
  854.                                                 DisplayBeep(PanelWindow -> WScreen);
  855.                                             }
  856.                                         }
  857.                                     }
  858.  
  859.                                     ReleaseWindow(PanelWindow);
  860.                                 }
  861.  
  862.                                 break;
  863.  
  864.                             case GAD_PAY1:
  865.  
  866.                                 TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT] = SZ_GetInteger(Gadget);
  867.  
  868.                                 MadeChanges = TRUE;
  869.  
  870.                                 break;
  871.  
  872.                             case GAD_PAY2:
  873.  
  874.                                 TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT] = SZ_GetInteger(Gadget);
  875.  
  876.                                 MadeChanges = TRUE;
  877.  
  878.                                 break;
  879.  
  880.                             case GAD_MINUTES1:
  881.  
  882.                                 TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT] = SZ_GetInteger(Gadget);
  883.  
  884.                                 MadeChanges = TRUE;
  885.  
  886.                                 break;
  887.  
  888.                             case GAD_MINUTES2:
  889.  
  890.                                 TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT] = SZ_GetInteger(Gadget);
  891.  
  892.                                 MadeChanges = TRUE;
  893.  
  894.                                 break;
  895.  
  896.                             case GAD_LIST:
  897.  
  898.                                 GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  899.                                     GTLV_Labels,~0,
  900.                                 TAG_DONE);
  901.  
  902.                                 if(TimeList)
  903.                                     FreeVec(TimeList);
  904.  
  905.                                 TimeDateNode = (struct TimeDateNode *)GetNode((struct List *)&Entry -> TimeDateList,Code);
  906.  
  907.                                 if(TimeList = BuildTimeList(TimeDateNode))
  908.                                 {
  909.                                     TimeSelected = 0;
  910.  
  911.                                     Selected = Code;
  912.  
  913.                                     DisableGadgets(GadgetArray,PanelWindow,FALSE);
  914.  
  915.                                     TimeDateNode = (struct TimeDateNode *)GetNode((struct List *)&Entry -> TimeDateList,Selected);
  916.  
  917.                                     GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
  918.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
  919.                                     TAG_DONE);
  920.  
  921.                                     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
  922.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
  923.                                     TAG_DONE);
  924.  
  925.                                     GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
  926.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
  927.                                     TAG_DONE);
  928.  
  929.                                     GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
  930.                                         GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
  931.                                     TAG_DONE);
  932.  
  933.                                     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  934.                                         GTLV_Labels,    TimeList,
  935.                                         GTLV_Selected,    0,
  936.                                         GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  937.                                     TAG_DONE);
  938.  
  939.                                     GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  940.                                         GA_Disabled,    FALSE,
  941.                                     TAG_DONE);
  942.  
  943.                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  944.                                         GA_Disabled,    TimeDateNode -> Table[0] . Count < 2,
  945.                                     TAG_DONE);
  946.  
  947.                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  948.                                         GA_Disabled,    FALSE,
  949.                                     TAG_DONE);
  950.  
  951.                                     if(Selected)
  952.                                     {
  953.                                         GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  954.                                             GA_Disabled,    FALSE,
  955.                                         TAG_DONE);
  956.  
  957.                                         GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  958.                                             GA_Disabled,    FALSE,
  959.                                         TAG_DONE);
  960.  
  961.                                         GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  962.                                             GA_Disabled,    FALSE,
  963.                                         TAG_DONE);
  964.                                     }
  965.                                     else
  966.                                     {
  967.                                         GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  968.                                             GA_Disabled,    TRUE,
  969.                                         TAG_DONE);
  970.  
  971.                                         GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  972.                                             GA_Disabled,    TRUE,
  973.                                         TAG_DONE);
  974.  
  975.                                         GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  976.                                             GA_Disabled,    TRUE,
  977.                                         TAG_DONE);
  978.                                     }
  979.                                 }
  980.                                 else
  981.                                 {
  982.                                     TimeDateNode = NULL;
  983.  
  984.                                     DisplayBeep(PanelWindow -> WScreen);
  985.  
  986.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  987.                                         GTLV_Labels,    ~0,
  988.                                     TAG_DONE);
  989.  
  990.                                     DisableGadgets(GadgetArray,PanelWindow,TRUE);
  991.  
  992.                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  993.                                         GA_Disabled,    TRUE,
  994.                                     TAG_DONE);
  995.  
  996.                                     GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  997.                                         GA_Disabled,    TRUE,
  998.                                     TAG_DONE);
  999.  
  1000.                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  1001.                                         GA_Disabled,    TRUE,
  1002.                                     TAG_DONE);
  1003.  
  1004.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1005.                                         GTLV_Labels,    &Entry -> TimeDateList,
  1006.                                         GTLV_Selected,    ~0,
  1007.                                     TAG_DONE);
  1008.  
  1009.                                     Selected = ~0;
  1010.  
  1011.                                     ActiveGadget = NULL;
  1012.  
  1013.                                     GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  1014.                                         GTLV_Labels,    &EmptyList,
  1015.                                         GTLV_Selected,    ~0,
  1016.                                         GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    TRUE,
  1017.                                     TAG_DONE);
  1018.  
  1019.                                     TimeSelected = ~0;
  1020.  
  1021.                                     GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  1022.                                         GA_Disabled,    TRUE,
  1023.                                     TAG_DONE);
  1024.  
  1025.                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  1026.                                         GA_Disabled,    TRUE,
  1027.                                     TAG_DONE);
  1028.  
  1029.                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  1030.                                         GA_Disabled,    TRUE,
  1031.                                     TAG_DONE);
  1032.                                 }
  1033.  
  1034.                                 break;
  1035.  
  1036.                             case GAD_IMPORT:
  1037.  
  1038.                                 BlockWindow(PanelWindow);
  1039.  
  1040.                                 GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1041.                                     GTLV_Labels,    ~0,
  1042.                                 TAG_DONE);
  1043.  
  1044.                                 MadeChanges |= ImportPanel(Entry,PhoneList);
  1045.  
  1046.                                 DisableGadgets(GadgetArray,PanelWindow,TRUE);
  1047.  
  1048.                                 GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  1049.                                     GA_Disabled,    TRUE,
  1050.                                 TAG_DONE);
  1051.  
  1052.                                 GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  1053.                                     GA_Disabled,    TRUE,
  1054.                                 TAG_DONE);
  1055.  
  1056.                                 GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  1057.                                     GA_Disabled,    TRUE,
  1058.                                 TAG_DONE);
  1059.  
  1060.                                 GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1061.                                     GTLV_Labels,    &Entry -> TimeDateList,
  1062.                                     GTLV_Selected,    ~0,
  1063.                                 TAG_DONE);
  1064.  
  1065.                                 Selected = ~0;
  1066.  
  1067.                                 ActiveGadget = NULL;
  1068.  
  1069.                                 GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  1070.                                     GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  1071.                                     GTLV_Selected,    0,
  1072.                                 TAG_DONE);
  1073.  
  1074.                                 TimeSelected = ~0;
  1075.  
  1076.                                 GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  1077.                                     GA_Disabled,    TRUE,
  1078.                                 TAG_DONE);
  1079.  
  1080.                                 GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  1081.                                     GA_Disabled,    TRUE,
  1082.                                 TAG_DONE);
  1083.  
  1084.                                 GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  1085.                                     GA_Disabled,    TRUE,
  1086.                                 TAG_DONE);
  1087.  
  1088.                                 ReleaseWindow(PanelWindow);
  1089.                                 break;
  1090.  
  1091.                             case GAD_ADDDAY:
  1092.                             case GAD_ADDDATE:
  1093.  
  1094.                                 BlockWindow(PanelWindow);
  1095.  
  1096.                                 MadeChanges = TRUE;
  1097.  
  1098.                                 if(NewNode = CreateTimeDateNode(0,1,"",2))
  1099.                                 {
  1100.                                     APTR OldActiveGadget = ActiveGadget;
  1101.                                     BYTE Result;
  1102.  
  1103.                                     if(Gadget -> GadgetID == GAD_ADDDAY)
  1104.                                     {
  1105.                                         NewNode -> Header . Month    = -1;
  1106.                                         NewNode -> Header . Day        = 0;
  1107.  
  1108.                                         Result = DayPanel(NewNode);
  1109.                                     }
  1110.                                     else
  1111.                                         Result = DatePanel(NewNode);
  1112.  
  1113.                                     if(Result)
  1114.                                     {
  1115.                                         AdaptTimeDateNode(NewNode);
  1116.  
  1117.                                         GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1118.                                             GTLV_Labels,    ~0,
  1119.                                         TAG_DONE);
  1120.  
  1121.                                         AddTail((struct List *)&Entry -> TimeDateList,&NewNode -> VanillaNode);
  1122.  
  1123.                                         Selected = Count++;
  1124.  
  1125.                                         GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1126.                                             GTLV_Labels,        &Entry -> TimeDateList,
  1127.                                             GTLV_Selected,        Selected,
  1128.                                             GTLV_Top,        Selected,
  1129.                                             GTLV_MakeVisible,    Selected,
  1130.                                         TAG_DONE);
  1131.  
  1132.                                         TimeDateNode = NewNode;
  1133.  
  1134. Redisplay:                                    if(TimeList)
  1135.                                             FreeVec(TimeList);
  1136.  
  1137.                                         if(TimeList = BuildTimeList(TimeDateNode))
  1138.                                         {
  1139.                                             if(TimeSelected == ~0)
  1140.                                                 TimeSelected = 0;
  1141.  
  1142.                                             DisableGadgets(GadgetArray,PanelWindow,FALSE);
  1143.  
  1144.                                             GT_SetGadgetAttrs(GadgetArray[GAD_PAY1],PanelWindow,NULL,
  1145.                                                 GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_FIRST_UNIT],
  1146.                                             TAG_DONE);
  1147.  
  1148.                                             GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES1],PanelWindow,NULL,
  1149.                                                 GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_FIRST_UNIT],
  1150.                                             TAG_DONE);
  1151.  
  1152.                                             GT_SetGadgetAttrs(GadgetArray[GAD_PAY2],PanelWindow,NULL,
  1153.                                                 GTIN_Number,    TimeDateNode -> Table[TimeSelected] . PayPerUnit[DT_NEXT_UNIT],
  1154.                                             TAG_DONE);
  1155.  
  1156.                                             GT_SetGadgetAttrs(GadgetArray[GAD_MINUTES2],PanelWindow,NULL,
  1157.                                                 GTIN_Number,    TimeDateNode -> Table[TimeSelected] . SecPerUnit[DT_NEXT_UNIT],
  1158.                                             TAG_DONE);
  1159.  
  1160.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  1161.                                                 GA_Disabled,    FALSE,
  1162.                                             TAG_DONE);
  1163.  
  1164.                                             GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  1165.                                                 GA_Disabled,    FALSE,
  1166.                                             TAG_DONE);
  1167.  
  1168.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  1169.                                                 GA_Disabled,    FALSE,
  1170.                                             TAG_DONE);
  1171.  
  1172.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  1173.                                                 GTLV_Labels,    TimeList,
  1174.                                                 GTLV_Selected,    TimeSelected,
  1175.                                                 GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  1176.                                             TAG_DONE);
  1177.  
  1178.                                             GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  1179.                                                 GA_Disabled,    FALSE,
  1180.                                             TAG_DONE);
  1181.  
  1182.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  1183.                                                 GA_Disabled,    TimeDateNode -> Table[0] . Count < 2,
  1184.                                             TAG_DONE);
  1185.  
  1186.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  1187.                                                 GA_Disabled,    FALSE,
  1188.                                             TAG_DONE);
  1189.  
  1190.                                             ActivateGadget(GadgetArray[GAD_PAY1],PanelWindow,NULL);
  1191.  
  1192.                                             ActiveGadget = GadgetArray[GAD_PAY1];
  1193.                                         }
  1194.                                         else
  1195.                                         {
  1196.                                             TimeDateNode = NULL;
  1197.  
  1198.                                             DisplayBeep(PanelWindow -> WScreen);
  1199.  
  1200.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1201.                                                 GTLV_Labels,    ~0,
  1202.                                             TAG_DONE);
  1203.  
  1204.                                             DisableGadgets(GadgetArray,PanelWindow,TRUE);
  1205.  
  1206.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  1207.                                                 GA_Disabled,    TRUE,
  1208.                                             TAG_DONE);
  1209.  
  1210.                                             GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  1211.                                                 GA_Disabled,    TRUE,
  1212.                                             TAG_DONE);
  1213.  
  1214.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  1215.                                                 GA_Disabled,    TRUE,
  1216.                                             TAG_DONE);
  1217.  
  1218.                                             GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1219.                                                 GTLV_Labels,    &Entry -> TimeDateList,
  1220.                                                 GTLV_Selected,    ~0,
  1221.                                             TAG_DONE);
  1222.  
  1223.                                             Selected = ~0;
  1224.  
  1225.                                             ActiveGadget = NULL;
  1226.  
  1227.                                             GT_SetGadgetAttrs(GadgetArray[GAD_TIME],PanelWindow,NULL,
  1228.                                                 GadToolsBase -> lib_Version < 39 ? TAG_IGNORE : GA_Disabled,    FALSE,
  1229.                                                 GTLV_Selected,    0,
  1230.                                             TAG_DONE);
  1231.  
  1232.                                             TimeSelected = ~0;
  1233.  
  1234.                                             GT_SetGadgetAttrs(GadgetArray[GAD_ADDTIME],PanelWindow,NULL,
  1235.                                                 GA_Disabled,    TRUE,
  1236.                                             TAG_DONE);
  1237.  
  1238.                                             GT_SetGadgetAttrs(GadgetArray[GAD_REMOVETIME],PanelWindow,NULL,
  1239.                                                 GA_Disabled,    TRUE,
  1240.                                             TAG_DONE);
  1241.  
  1242.                                             GT_SetGadgetAttrs(GadgetArray[GAD_EDITTIME],PanelWindow,NULL,
  1243.                                                 GA_Disabled,    TRUE,
  1244.                                             TAG_DONE);
  1245.                                         }
  1246.                                     }
  1247.                                     else
  1248.                                     {
  1249.                                         FreeVec(NewNode);
  1250.  
  1251.                                         if(ActiveGadget = OldActiveGadget)
  1252.                                             ActivateGadget(OldActiveGadget,PanelWindow,NULL);
  1253.                                     }
  1254.                                 }
  1255.  
  1256.                                 ReleaseWindow(PanelWindow);
  1257.  
  1258.                                 break;
  1259.  
  1260.                             case GAD_REMOVE:
  1261.  
  1262.                                 if(--Count)
  1263.                                 {
  1264.                                     if(TimeDateNode -> VanillaNode . ln_Succ -> ln_Succ)
  1265.                                         NewNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1266.                                     else
  1267.                                         NewNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Pred;
  1268.                                 }
  1269.  
  1270.                                 MadeChanges = TRUE;
  1271.  
  1272.                                 GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1273.                                     GTLV_Labels,    ~0,
  1274.                                 TAG_DONE);
  1275.  
  1276.                                 Remove(TimeDateNode);
  1277.  
  1278.                                 FreeVec(TimeDateNode);
  1279.  
  1280.                                 if(Count > 1)
  1281.                                 {
  1282.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1283.                                         GTLV_Labels,    &Entry -> TimeDateList,
  1284.                                         GTLV_Selected,    Count,
  1285.                                     TAG_DONE);
  1286.  
  1287.                                     TimeDateNode = NewNode;
  1288.  
  1289.                                     goto Redisplay;
  1290.                                 }
  1291.                                 else
  1292.                                 {
  1293.                                     DisableGadgets(GadgetArray,PanelWindow,TRUE);
  1294.  
  1295.                                     GT_SetGadgetAttrs(GadgetArray[GAD_EDIT],PanelWindow,NULL,
  1296.                                         GA_Disabled,    TRUE,
  1297.                                     TAG_DONE);
  1298.  
  1299.                                     GT_SetGadgetAttrs(GadgetArray[GAD_CLONE],PanelWindow,NULL,
  1300.                                         GA_Disabled,    TRUE,
  1301.                                     TAG_DONE);
  1302.  
  1303.                                     GT_SetGadgetAttrs(GadgetArray[GAD_REMOVE],PanelWindow,NULL,
  1304.                                         GA_Disabled,    TRUE,
  1305.                                     TAG_DONE);
  1306.  
  1307.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1308.                                         GTLV_Labels,    &Entry -> TimeDateList,
  1309.                                         GTLV_Selected,    ~0,
  1310.                                     TAG_DONE);
  1311.  
  1312.                                     ActiveGadget = NULL;
  1313.  
  1314.                                     TimeDateNode = NULL;
  1315.                                 }
  1316.  
  1317.                                 break;
  1318.  
  1319.                             case GAD_CLONE:
  1320.  
  1321.                                 if(NewNode = CreateTimeDateNode(0,1,"",TimeDateNode -> Table[0] . Count))
  1322.                                 {
  1323.                                     MadeChanges = TRUE;
  1324.  
  1325.                                     CopyMem(TimeDateNode,NewNode,sizeof(struct TimeDateNode));
  1326.  
  1327.                                     NewNode -> VanillaNode . ln_Name = NewNode -> Buffer;
  1328.  
  1329.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1330.                                         GTLV_Labels,    ~0,
  1331.                                     TAG_DONE);
  1332.  
  1333.                                     AddTail((struct List *)&Entry -> TimeDateList,&NewNode -> VanillaNode);
  1334.  
  1335.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1336.                                         GTLV_Labels,    &Entry -> TimeDateList,
  1337.                                         GTLV_Selected,    Count++,
  1338.                                     TAG_DONE);
  1339.  
  1340.                                     TimeDateNode = NewNode;
  1341.  
  1342.                                     goto Redisplay;
  1343.                                 }
  1344.  
  1345.                                 break;
  1346.  
  1347.                             case GAD_EDIT:
  1348.  
  1349.                                 BlockWindow(PanelWindow);
  1350.  
  1351.                                 {
  1352.                                     struct Gadget *OldActiveGadget = ActiveGadget;
  1353.  
  1354.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1355.                                         GTLV_Labels,    ~0,
  1356.                                     TAG_DONE);
  1357.  
  1358.                                     if(TimeDateNode -> Header . Month == -1)
  1359.                                         MadeChanges |= DayPanel(TimeDateNode);
  1360.                                     else
  1361.                                         MadeChanges |= DatePanel(TimeDateNode);
  1362.  
  1363.                                     AdaptTimeDateNode(TimeDateNode);
  1364.  
  1365.                                     GT_SetGadgetAttrs(GadgetArray[GAD_LIST],PanelWindow,NULL,
  1366.                                         GTLV_Labels,    &Entry -> TimeDateList,
  1367.                                         GTLV_Selected,    Selected,
  1368.                                     TAG_DONE);
  1369.  
  1370.                                     if(ActiveGadget = OldActiveGadget)
  1371.                                         ActivateGadget(OldActiveGadget,PanelWindow,NULL);
  1372.                                 }
  1373.  
  1374.                                 ReleaseWindow(PanelWindow);
  1375.  
  1376.                                 break;
  1377.                         }
  1378.                     }
  1379.                 }
  1380.             }
  1381.  
  1382.             RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  1383.  
  1384.             PopWindow();
  1385.  
  1386.             CloseWindow(PanelWindow);
  1387.  
  1388.             if(TimeList)
  1389.                 FreeVec(TimeList);
  1390.         }
  1391.  
  1392.         FreeGadgets(GadgetList);
  1393.     }
  1394.  
  1395.     ActiveGadget = NULL;
  1396.  
  1397.     return(MadeChanges);
  1398. }
  1399.